<template>
  <div class="container" style="padding:25px">
    <div class="row">
      <div class="col-md-12 my-3">
        <h2>Room</h2>
        <el-input style="width:200px"  v-model="roomId"/>
      </div>
    </div>
    <div class="row">
      <div class="col-md-12">
        <div class="">
          <vue-webrtc ref="webrtc"
                      width="100%"
                      :roomId="roomId"
                      :socketURL="'192.168.10.11'"
                      v-on:joined-room="logEvent"
                      v-on:left-room="logEvent"
                      v-on:opened-room="logEvent"
                      v-on:share-started="logEvent"
                      v-on:share-stopped="logEvent"
                      @error="onError" />
        </div>
        <div class="row">
          <div class="col-md-12 my-3" style="margin-top:20px">
            <el-button type="primary" class="btn btn-primary" @click="onJoin">加入房间</el-button>
            <el-button type="primary" class="btn btn-primary" @click="onLeave">离开房间</el-button>
            <el-button type="primary" class="btn btn-primary" @click="onCapture">视频捕获</el-button>
            <el-button type="primary" class="btn btn-primary" @click="onShareScreen">分享屏幕</el-button>
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-12">
        <h2>Captured Image</h2>
        <figure class="figure">
          <img :src="img" class="img-responsive" />
        </figure>
      </div>
    </div>
  </div>
</template>



<script>
  import Vue from 'vue'
  import {WebRTC} from 'vue-webrtc'
  Vue.component(WebRTC.name, WebRTC);
  // roomId 房间id 
  // cameraHeight  视频元素的高度 
  // socketURL        信令服务器的 URL，使用这个默认值或运行你自己的，见 .\vue-webrtc-lobby
  // autoplay
  // screenshotFormat  截图格式
  // enableAudio       在加入时启用音频
  // enableVideo       在加入时启用视频
  // enableLogs         启用 webrtc 控制台日志
  // deviceId         从 navigator.mediaDevices.enumerateDevices() 将视频设备 ID 设置为相机
  // peerOptions
  export default {
    name: 'app',
    components: {
    },
    data() {
      return {
        img: null,
        roomId: "public-room-v2"
      };
    },
    computed: {
    },
    watch: {
    },
    methods: {
      onCapture() {
        this.img = this.$refs.webrtc.capture();
      },
      onJoin() {
        this.$refs.webrtc.join();
      },
      onLeave() {
        this.$refs.webrtc.leave();
      },
      onShareScreen() {
        this.img = this.$refs.webrtc.shareScreen();
      },
      onError(error, stream) {
        console.log('On Error Event', error, stream);
      },
      logEvent(event) {
        console.log('Event : ', event);
      },
    }
  };
</script>
